home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12365 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Correct input from user.
  5. Date: 30 Mar 1996 15:16 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <30MAR199615162182@erich.triumf.ca>
  9. References: <4jjfur$5fu@dfw-ixnews6.ix.netcom.com>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4jjfur$5fu@dfw-ixnews6.ix.netcom.com>, egurevit@soleil.acomp.usf.edu (Eric Gurevitz) writes...
  14. >I am writing for school. The program is to take the interest rate,
  15. >number of years, and principal amount and return the monthly payment.
  16. >For each of the things I ask the user I am using a scanf and storing
  17. >it as a float. I would like to make a loop so that is the user types a
  18. >lettter when asked for a number it prints an error message and tell
  19. >them to try again. I am using GCC and writing it in C. Thnaks for the
  20. >help. 
  21.  
  22. Use fgets() to get the input, then convert it (if possible) with sscanf(). 
  23. Check the return value of sscanf() to see if it was successful, or/and check
  24. the buffer for appropriate chars before trying the conversion.  It is generally
  25. a bad idea to use scanf() for direct user input.
  26.  
  27. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  28. Internet: bennett@triumf.ca         | of one another only when one can be
  29. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  30. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  31. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  32. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  33.  
  34.